<template>
	<view style="padding: 15px; box-sizing: border-box;">
		<uni-section title="项目明细" type="line">
			<div style="padding: 10px;">
				<view class="item-detail" v-for="(item, index) in detailList" :key="index">
					<p>开单时间：{{item.BillTime}}</p>
					<p>开单科室：{{item.DepartmentName}}</p>
					<!-- <p>开单医生：{{item.Doctor}}</p> -->
					<p>项目名称：{{item.ItemName}}</p>
					<p>项目费用：￥{{item.ItemMoney}}</p>
					<p>就诊人：{{item.Name}}</p>
				</view>
				
				<p class="total-price">总费用：￥{{item.Money}} <span v-if="item.Ifpay == '2'" style="color: red;">（已退款）</span></p>
			</div>
		</uni-section>
		<div style="margin-top: 10px;"></div>
		<u-button v-if="item.ChargeStatus == '已退费' && item.Ifpay == '1'" type="error" text="退款" @click="refund()"></u-button>
		
		<yangr-msg v-if="yangrMsgShow" :title="yangrMsgTitle" type="error" :info="yangrMsgMessage" btn="确定"
			@yangrMsgEvent="closeYangrMsg"></yangr-msg>
	</view>
</template>

<script>
	import yangrMsg from "@/components/yangr-msg/yangr-msg.vue"
	export default {
		components: {
			yangrMsg
		},
		data() {
			return {
				item: {},
				detailList: [],
				openid: '',
				currentUserCard: {},
				
				yangrMsgTitle: '操作失败',
				yangrMsgMessage: '',
				yangrMsgShow: false
			}
		},
		onLoad(option) {
			this.currentUserCard = uni.getStorageSync('current_user_card')
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('detail', (data) => {
				this.item = data.data
				this.api_paiddetail(this.item.BillId)
			})
		},
		methods: {
			closeYangrMsg() {
				this.yangrMsgShow = false
			},
			api_paiddetail(billid) {
				let openid = uni.getStorageSync('openid')
				let numcard = uni.getStorageSync('current_user_card').numcard
				this.detailList = []
				this.$app._post_form2("entry/wxapp/apipayment.paiddetail", {
					"cardid": numcard,
					"openid": openid,
					"billid": billid
				}, (res) => {
					console.log(res)
					this.detailList = res.data
				})	
			},
			
			/**
			 * 退款
			 */
			refund() {
				console.log(this.item)
				uni.showModal({
					title: '提示',
					content: '确定要退款吗？',
					success: (res) => {
						if (res.confirm) {
							let openid = uni.getStorageSync('openid')
							this.$app._post_form2("entry/wxapp/apipayment.billrefund", {
								"cardid": this.currentUserCard.numcard,
								"billid": this.item.BillId,
								"money": this.item.Money,
								"openid": openid,
								"billtime": this.item.BillTime
							}, (res) => {
								if (res.status == 0) {
									uni.navigateTo({
										url: '/pages/global/successMessage?msg=退款成功'
									})
								}else {
									// uni.showToast({
									// 	icon: 'none',
									// 	title: '退款失败'
									// })
									this.yangrMsgShow = true
									this.yangrMsgMessage = '退款失败'
								}
							})	
						} else if (res.cancel) {
				
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item-detail {
		border-radius: 6px;
		border: 1px solid #e3e3e3;
		padding: 10px;
		line-height: 30px;
		background-color: #f5f5f5;
		font-size: .9rem;
		color: #757575;
		margin-bottom: 5px;
	}
	.total-price {
		font-size: 1.1rem;
		color: #ff9800;
		line-height: 30px;
	}
</style>